package com.jdk.demo.thread.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.function.Supplier;

// 两个CompletionStage，谁执行返回的结果快，我就用那个CompletionStage的结果进行下一步的转化操作
public class ApplyToEitherDemo {

	public static void main(String[] args) throws Exception {
		CompletableFuture<String> future1 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello1";
	        }
	    });
	    CompletableFuture<String> future2 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello2";
	        }
	    });
	    CompletableFuture<String> result = future1.applyToEither(future2, new Function<String, String>() {
	        @Override
	        public String apply(String t) {
	            return t;
	        }
	    });
	    System.out.println(result.get());
	}

}
